//
//  ViewController.m
//  手动创建Layer
//
//  Created by 伍银荣 on 2021/7/12.
//  Copyright © 2021 com.WYR. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@property (nonatomic, weak) CALayer *layer;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //手动创建layer
    CALayer *layer = [[CALayer alloc]init];
    layer.backgroundColor = [UIColor redColor].CGColor;
    //大小
    layer.bounds = CGRectMake(0, 0, 100, 100);
    //位置
    layer.position = CGPointMake(200, 200);
    
    //设置图层的边框
    layer.borderColor = [UIColor greenColor].CGColor;
    layer.borderWidth = 10;
    
    layer.shadowColor = [UIColor blueColor].CGColor;
    layer.shadowRadius = 20;
    layer.shadowOffset = CGSizeMake(50, 50);
    layer.shadowOpacity = 1;
    
    layer.contents = (__bridge id)([UIImage imageNamed:@"樱桃小丸子"].CGImage);
    
    //layer.cornerRadius = 50;
    //layer.masksToBounds = YES;
    
    [self.view.layer addSublayer:layer];
     self.layer = layer;
    
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
//    //凡是被Animatable.修饰过的属性都是可动画属性,他们都叫隐式动画,自动带有动画,控件的根layer没有隐式动画
//    //self.layer.bounds = CGRectMake(0, 0, 200, 200);
//    //获取触摸对象
//    UITouch *t = touches.anyObject;
//    //获取当前手指所在的位置
//    CGPoint currentPoint = [t locationInView:t.view];
//
//    //如果想要取消隐式动画,需要禁用隐式动画(事务)
//    //1.开启事务
//    [CATransaction begin];
//
//    //禁用隐式动画
//    [CATransaction setDisableActions:YES];
//
//    //让layer跑到手指的位置(这一句一定要写在中间)
//    self.layer.position = currentPoint;
//
//    //提交事务
//    [CATransaction commit];
    
    
    //CALyer的transform属性(3D立体的效果)
    //旋转
    self.layer.transform = CATransform3DRotate(self.layer.transform, M_PI_4, 0, 0, 1);
    
    //缩放(z轴无效)
   // self.layer.transform = CATransform3DScale(self.layer.transform, 1, 1, 0.5);
    
    //平移(z轴无效)
    self.layer.transform = CATransform3DTranslate(self.layer.transform, 0, 0, 10);
    
    
    
    
}


@end
